package com.yanqu.road.server.cmd.platform;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
@CmdApi(respMsg = ActivityProto.ActivityGetRewardRespMsg.class)
@Cmd(code = Protocol.S_PLATFORM_COMPONENT_EVALUATE, desc = "小游戏专属评价组件接入-领奖")
public class PlatformComponentEvaluateRewardCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        AttributeModule attributeModule = player.getModule(AttributeModule.class);
        long attrValue = attributeModule.getAttribute(ePlayerAttrType.PlatformComponentEvaluateReward);
        if(attrValue > 0){
            ret = GameErrorCode.E_ACTIVITY_REWARD_IS_GET;
            return;
        }
        attributeModule.setAttribute(ePlayerAttrType.PlatformComponentEvaluateReward, 1);
        String reward = GameConfig.APPLETS_ASSESS_REWARD;
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.PlatformActivity, eLogMoneyType.PlatformComponentEvaluateRewardReward);
        player.sendPacket(Protocol.U_PLATFORM_COMPONENT_EVALUATE, ActivityProto.ActivityGetRewardRespMsg.newBuilder().setRet(0).setReward(reward));
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_PLATFORM_COMPONENT_EVALUATE, ActivityProto.ActivityGetRewardRespMsg.newBuilder().setRet(ret));
        }
    }
}
